package com.example.administrator.text.Framgnet;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.example.administrator.text.AppointTimeActivity;
import com.example.administrator.text.R;
import org.apache.log4j.Logger;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import adapter.RecyclerWeWiFiAccount;
import app.MyApplication;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import data.SharedPreferencesUtils;
import util.AgentIp;
import util.BReceiverUtil.AlarmReceiver;
import util.GreenTreeNetworkUtil;
import util.HomeUtil;
import util.JumpActivityUtils;
import util.LogUtil;
import util.NetUtils;
import util.NetWorkstateUtil;
import util.RequestDataCallback;
import util.StringUtil;
import util.Url;
import util.WiFiShowFV;
import util.WifiUtil;
import util.getInformation;
import util.serviceUtil.MyService;
import view.MySwipeRefreshLayout;
import view.SmartScrollView;
import view.diaLogView.CommomDialog;
import view.diaLogView.CouponDialog;
import view.diaLogView.CrowdRetunDialog;
import view.diaLogView.EntryPromptDialog;
import view.diaLogView.RetunDialog;
import static com.example.administrator.text.WelComeActvity.mWelComeVP;
import static data.SharedPreferencesUtils.getParam;
import static data.SharedPreferencesUtils.setParam;

/**
 *wifi 页的相关信息
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class WiFiFragment extends Fragment{
    private static boolean ismJudge = false; //避免一进去就 两次
    private String mId,mToken,mFwq;
    private String mWevVip = "";
    private List<ScanResult> mList;
    private WiFiShowFV mWiFiShowFV;
    private HashMap<String,Object> mMap;
    private EntryPromptDialog mEntryPromptDialog;
    private int mPollingNumber,mNetWorkstate= 1;
    private int mTime;//总时长
    private boolean mJudge = false;    //判断是否加载过wifi列表
    private boolean mNetworking = true; //true为可以点击 上网、断网、切换、按钮
    private boolean mAgainState = true; //是否需要重新登录
    private MySwipeRefreshLayout mSwipeRefreshLayout;
    private Logger mLogger = Logger.getLogger(WiFiFragment.class);
    public static String mNewFiWiFi = "NewFi";   //牛wifi的SSID
    private RecyclerWeWiFiAccount mRecyclerWeWiFiAccount;
    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(mHandler.hasMessages(1)){
                mHandler.removeMessages(1);
            }

            if(mHandler.hasMessages(3)){
                mHandler.removeMessages(3);
            }
            switch (msg.what){
                case 1:
                   handlerMsg1();
                    break;
                case 2:
                  break;
                case 3:
                    handlerMsg3();
                  break;
            }
        }
    };

    @Bind(R.id.fragment_wifi_sv)         SmartScrollView mSmartScrollView;
    @Bind(R.id.wifif_recyclerView_list)  RecyclerView mRecyclerView;
    @Bind(R.id.wifif_welfare_list)       RecyclerView mRVWelfare;   //福利的图片
    @Bind(R.id.fragment_wifi_upward)     FrameLayout mFrameLayoutMap;
    @Bind(R.id.fragment_wifi_tv_time)    TextView mTVTime;          //时间
    @Bind(R.id.fragment_wifi_tv_name)    TextView mTVWiFiName;     //连接的wifi名
    @Bind(R.id.fragment_wifi_tv_newfi)   TextView mTVNewFi;       //操作wifi的按钮
    @Bind(R.id.fragment_wifi_tv_renew)   TextView mTVRenew;      //我要续时
    @Bind(R.id.fragment_wifi_iv_1)       ImageView mIVRing;     //外环
    @Bind(R.id.fragment_wifi_iv)         ImageView mIVWiFi;    //wifi的状态
    @Bind(R.id.fragment_wifi_pb)         ProgressBar mPBRing; //外环转圈
    @Bind(R.id.fragment_wifi_view)        View mView;
    @Bind(R.id.fragment_wifi_iv_time)     ImageView mIV1;   //中间的图标1
    @Bind(R.id.fragment_wifi_iv_recommend)ImageView mIV2;   //中间的图标2
    @Bind(R.id.fragment_wifi_iv_charge)   ImageView mIV3;   //中间的图标3
    @Bind(R.id.fragment_wifi_tv1_time)    TextView mTV1;    //中间的文字1
    @Bind(R.id.fragment_wifi_tv_recommend)TextView mTV2;    //中间的文字2
    @Bind(R.id.fragment_wifi_tv_charge)   TextView mTV3;    //中间的文字3
    @Bind(R.id.fragment_ll_middle)        LinearLayout mLLMiddle;

    public WiFiFragment() {

    }

    public static WiFiFragment newInstance() {
        return new WiFiFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_wifi, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        EventBus.getDefault().register(this);
        init(view);
    }

    /**
     * 上面的头部
     */
    @OnClick(R.id.fragment_wifi_iv_2)
    void wifi_iv_2(){
      if(mTVNewFi.getText().toString().equals(getString(R.string.wifi_networking))){
          mNetworking = false;
          getJudge();
      }
    }

    /**
     * 切换到newFi(或者是开发wifi设置)42b369d0
     */
    @OnClick(R.id.fragment_wifi_tv_newfi)
    void newFi(){
        LogUtil.eE("","....."+mNetworking);
        if(mNetworking){
            if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 0){
                mPollingNumber = 1;
                mJudge = false;
                mNetworking = false;
                WifiUtil.getInstance(getActivity()).openWifi();
                mHandler.sendEmptyMessageDelayed(1,1000);
                mTVNewFi.setText(R.string.wifi_networking);
                mTVWiFiName.setText("正在连接网络...");
                mIVWiFi.setBackgroundResource(R.mipmap.wifi_space);
                mIVRing.setVisibility(View.GONE);
                mPBRing.setVisibility(View.VISIBLE);
            }else if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 1){
                String tvName = mTVNewFi.getText().toString();
                if(tvName.equals("上网")){
                    mNetworking = false;
                    mLogger.info("联网处理....string.。。。。点击了。。。。。。。1。。.");
                    getJudge();
                    handlerMsg4();
                }else if(tvName.equals("断开")){
                    mNetworking = false;
                    breakoff();
                }else if(tvName.equals("切换至NewFi") || tvName.equals("连接NewFi")){
                    mTVNewFi.setText(R.string.wifi_networking);
                    mTVWiFiName.setText("正在切换WiFi...");
                    mPollingNumber = 1;
                    mJudge = false;
                    mNetworking = false;
                    mIVRing.setVisibility(View.GONE);
                    mPBRing.setVisibility(View.VISIBLE);
                    mHandler.sendEmptyMessageDelayed(3,1000);
                    int newFiID = WifiUtil.getInstance(getActivity()).IsConfiguration("\""+mNewFiWiFi+"\"");
                    if(newFiID>0) {
                        boolean d = WifiUtil.getInstance(getActivity()).ConnectWifi(newFiID);
                        if (!d) {
                            WifiUtil.getInstance(getActivity()).ConnectWifi(WifiUtil.getInstance(getActivity()).IsConfiguration(mNewFiWiFi));
                        }
                    }
                }
            }else {
                Toast.makeText(getActivity(),"请先连接网络",Toast.LENGTH_SHORT).show();
            }
        }
    }

    /**
     * 地图
     */
    @OnClick(R.id.fragment_wifi_upward)
    void upward(){
        JumpActivityUtils.getInstance().jumpMap(getActivity(),"wifi");
    }

    /**
     * 我要续时
     */
    @OnClick(R.id.fragment_wifi_tv_renew)
    void renew(){

        AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
            @Override
            public void onClick(boolean state){
                if(state){
                    JumpActivityUtils.getInstance().jumpAppointTime(getActivity(),AppointTimeActivity.mRenew,"");
                }else {
                    mLogger.info("联网处理....string.。。。。点击了。。。。。。。1。。.");
                    mNetworking = false;
                    getJudge();
                    handlerMsg4();
                }
            }
        });

    }

    /**
     * 充值右边
     */
    @OnClick(R.id.fragment_wifi_ll_charge)
    void charge(){
        String type = mTV3.getText().toString();
        if(type.equals("时长充值")){
            if((boolean) getParam(getActivity(),HomeUtil.mVIPSTATE,true)) {
                JumpActivityUtils.getInstance().jumpTimeRecharge(getActivity(),"");
            }else {

                Toast.makeText(getActivity(),"您现在还不是会员，请先加入会员", Toast.LENGTH_SHORT).show();
                JumpActivityUtils.getInstance().jumpWebView(getActivity(), Url.mATIAIRIP + Url.getUrlNew().vipdePosit+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+MyApplication.getApp().getmPattern(), "会员购买");
            }
        }else if(type.equals("套餐充值")){

               mWevVip = (int) getParam(getActivity(), HomeUtil.mVIPCombonum,1)+"";
               String url = Url.mATIAIRIP +Url.getUrlNew().vipdePosit+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+MyApplication.getApp().getmPattern();
               JumpActivityUtils.getInstance().jumpWebView(getActivity(),url,"套餐购买");

        }else if(type.equals("选择模式")){
            JumpActivityUtils.getInstance().jumpWeBinDingPhone(getActivity(),"","WiFi");
        }else {
            Toast.makeText(getActivity(),getString(R.string.move_network), Toast.LENGTH_SHORT).show();
        }
    }

    /**
     *我的时长   左边
     */
    @OnClick(R.id.fragment_wifi_ll_time)
    void showTime(){
        String type =  mTV1.getText().toString();
        if(type.equals("可用时长")){
            if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                JumpActivityUtils.getInstance().jumpWeTime(getActivity());
            }
        }else if(type.equals("我的套餐")){
            mWevVip = (int) getParam(getActivity(), HomeUtil.mVIPCombonum,1)+"";
            LogUtil.eE("VIPSTATE",""+(boolean) getParam(getActivity(),HomeUtil.mVIPSTATE,true));
            if((boolean) getParam(getActivity(),HomeUtil.mVIPSTATE,true)){
                    String url = Url.mATIAIRIP +Url.getUrlNew().vipmySelf+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+MyApplication.getApp().getmPattern();
                    JumpActivityUtils.getInstance().jumpWebView(getActivity(),url,"套餐");
            }else {
                Toast.makeText(getActivity(),"您还没有购买套餐，请先购买套餐", Toast.LENGTH_SHORT).show();
                String url = Url.mATIAIRIP +Url.getUrlNew().vipdePosit+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+MyApplication.getApp().getmPattern();
                JumpActivityUtils.getInstance().jumpWebView(getActivity(),url,"套餐购买");
            }
        }else if(type.equals("剩余时间")){
            Toast.makeText(getActivity(),"请先选择模式",Toast.LENGTH_SHORT).show();
            JumpActivityUtils.getInstance().jumpWeBinDingPhone(getActivity(),"","WiFi");
        }else {
            Toast.makeText(getActivity(),getString(R.string.move_network), Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 分享  中间
     */
    @OnClick(R.id.fragment_wifi_ll_recommend)
    void recommend(){
        int pattern = StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern());
        if(pattern == 1 || pattern == 2){
            JumpActivityUtils.getInstance().jumpShare(getActivity());
        }else if(pattern == 0){
                Toast.makeText(getActivity(),getString(R.string.move_network), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        LogUtil.eE("","..........onDetach..........WIFi..");
        if(mHandler !=null){mHandler.removeCallbacksAndMessages(null);}

        if(mList !=null){mList.clear();}

        if(mWiFiShowFV !=null){mWiFiShowFV.onShop();}

        if(mEntryPromptDialog !=null){mEntryPromptDialog.dismiss();}
        EventBus.getDefault().unregister(this);
    }

    private void init(View view) {
        mNetworking = true;
        LinearLayoutManager linearLayoutManagaer = new LinearLayoutManager(getActivity()){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        LinearLayoutManager linearLayoutManagaer1 = new LinearLayoutManager(getActivity()){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        linearLayoutManagaer.setOrientation(LinearLayout.VERTICAL);
        mRecyclerView.setLayoutManager(linearLayoutManagaer);
        mRecyclerView.setHasFixedSize(true);//如果确定每个item的内容不会改变RecyclerView的大小，设置这个选项可以提高性能
        mRecyclerView.setFocusable(false);

        mRVWelfare.setLayoutManager(linearLayoutManagaer1);
        mRVWelfare.setHasFixedSize(true);//如果确定每个item的内容不会改变RecyclerView的大小，设置这个选项可以提高性能
        mRVWelfare.setFocusable(false);

        pullRefresh(view);

        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 0){
            mIVRing.setVisibility(View.VISIBLE);
            mPBRing.setVisibility(View.GONE);
            mTVRenew.setVisibility(View.GONE);
            mIVWiFi.setBackgroundResource(R.mipmap.wifi_4g);
            mTVWiFiName.setText("请打开Wi-Fi,土豪除外哦...");
            mTVNewFi.setText("去设置");

        }else if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 1){
            setAdapterWifiList(0);
             if(AgentIp.newInstance(getActivity()).isNetWorkstate()){
                 mIVWiFi.setBackgroundResource(R.mipmap.wifi_full);
             }else {
                 mIVWiFi.setBackgroundResource(R.mipmap.wifi_nothing);
             }

               if(MyApplication.getApp().getSiteAreaid() >= 10000){
                   if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) != 1){
                       mLogger.info("联网处理....string.。。。。自动联网。。。。。。。1。。.");
                       if((boolean) getParam(getActivity(),HomeUtil.mVIPSTATE,true)){
                           getJudge();
                           handlerMsg4();
                           mNetworking = false;
                       }
                   }
               }
        }

        mId = (String) getParam(getActivity(), HomeUtil.mUseridDB,"");
        mToken = (String) getParam(getActivity(), HomeUtil.mTokenDB, "");
        mWevVip = (int) getParam(getActivity(), HomeUtil.mVIPCombonum,1)+"";
        LogUtil.eE("","getSiteAreaid...."+MyApplication.getApp().getSiteAreaid());
            if(MyApplication.getApp().getSiteAreaid() != 1 && MyApplication.getApp().getSiteAreaid() != 2 ){
                getCoupon();
            }
            wifiView(0);
        if(MyApplication.getApp().getSiteAreaid() >= 1000){
            mFrameLayoutMap.setVisibility(View.GONE);
        }else {
            mFrameLayoutMap.setVisibility(View.GONE);
        }
        Intent intent1 = new Intent(getActivity(),AlarmReceiver.class);
        intent1.putExtra("networking","updateNetwork6");
        getActivity().sendBroadcast(intent1);
        HomeUtil.getHemeUtilNew().getHandlerNew().postDelayed(new Runnable() {@Override public void run() {ismJudge = true;}},1500);
        getWelfareData();
        initWebView();
    }

    /**
     *显示wifil列表信息
     */
    private void setAdapterWifiList(final int type){
        mList = WifiUtil.getInstance(getActivity()).getWifiList();
        if(mList !=null){
            mRecyclerWeWiFiAccount = new RecyclerWeWiFiAccount(getActivity(),2,null,mList,null);
            mRecyclerView.setAdapter(mRecyclerWeWiFiAccount);
        }else {
            mView.setVisibility(View.GONE);
        }
        if(!mJudge){
            gWifiView(WifiUtil.getInstance(getActivity()).getWIFIName(),type,AgentIp.newInstance(getActivity()).isNetWorkstate());
        }
    }

    /**
     *下拉刷新
     */
    private void pullRefresh(View view){

        mSwipeRefreshLayout = (MySwipeRefreshLayout) view.findViewById(R.id.fragment_wifi_myswiperl);
        mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                LogUtil.eE("","onRefresh.......");
                if(MyApplication.getApp().getSiteAreaid() !=0){
                    mList = WifiUtil.getInstance(getActivity()).getWifiList();
                    if(mList !=null && mRecyclerWeWiFiAccount !=null){
                        mRecyclerWeWiFiAccount.showView(mList);
                        mRecyclerWeWiFiAccount.notifyDataSetChanged();
                    }
                    NetWorkstateUtil.getInstance().getNetWorkState(getActivity(), new NetWorkstateUtil.NetworkingOnClickListener() {
                        @Override
                        public void onItemClick(boolean state) {
                            mSwipeRefreshLayout.setRefreshing(false);
                            mNetworking = true;
                            mIVRing.setVisibility(View.VISIBLE);
                            mPBRing.setVisibility(View.GONE);
                            setTextViewText(WifiUtil.getInstance(getActivity()).getWIFIName(),state,1);
                        }
                    });
                    if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                        queryBalance();
                    }else if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 2){
                        int days = (int)SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mPackage_RemainingDays,0);
                        if(days > 0){
                            mTVTime.setText(days+"天");
                        }else {
                            mTVTime.setText(0+"天");
                        }
                    }

                }else {mSwipeRefreshLayout.setRefreshing(false);}
            }
        });
    }

    /*** 订阅事件FirstEvent*/
    @Subscribe
    public void onEventMainThread(final String string){
        mLogger.info("onEventMainThread()....string.."+string);
        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() !=0){
            mNetworking = true;
            if(string !=null && !string.equals("")){
                try {
                    JSONObject jsonObject = new JSONObject(string);
                    if(jsonObject.getString("code").equals("WiFi")){
                        if(jsonObject.getString("target").equals(AppointTimeActivity.mNetWorkstate)){
                            mTVNewFi.setVisibility(View.GONE);
                            mIVRing.setVisibility(View.VISIBLE);
                            mPBRing.setVisibility(View.GONE);
                            if(MyApplication.getApp().getSiteAreaid() == 10003){
                                if((int) getParam(getActivity(),"altair",3) == 10003){
                                    mTVRenew.setVisibility(View.GONE);
                                }else {
                                    showRenew();
                                }
                            }else {
                                showRenew();
                            }

                            if(MyApplication.getApp().getSiteAreaid() != 1 && MyApplication.getApp().getSiteAreaid() != 2 ){
                                if(jsonObject.getString("sign").equals("chonglian")){
                                    if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                                        Url.getUrlNew().setNotification(true);
                                        setTextViewText(WifiUtil.getInstance(getActivity()).getWIFIName(),true,0);
                                    }
                                }else if(jsonObject.getString("sign").equals(AppointTimeActivity.mbreakNetWorkstate)){
                                    mTVNewFi.setText(R.string.wifi_networking);
                                    mTVRenew.setVisibility(View.GONE);
                                    mTVWiFiName.setText("已连接"+WifiUtil.getInstance(getActivity()).getWIFIName()+"畅享网络");
                                }else if(jsonObject.getString("sign").equals(AppointTimeActivity.mPackage_NetWorkstate)){
                                    mTVNewFi.setVisibility(View.GONE);
                                    mTVRenew.setVisibility(View.GONE);
                                    mTVWiFiName.setText("已连接"+WifiUtil.getInstance(getActivity()).getWIFIName()+"畅享网络");
                                    if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                                        Url.getUrlNew().setNotification(true);
                                         inspectTVTime(0,true);
                                     }
                                }
                            }

                            if(jsonObject.getString("sign").equals("UpdateUI")){
                                setTextViewText(WifiUtil.getInstance(getActivity()).getWIFIName(),true,0);
                            }

                        }else if(jsonObject.getString("target").equals("vip")){
                            int time = jsonObject.getInt("time");
                            if(time>0){
                                mTVTime.setText((mTime+time)+"h");
                            }
                        }else if(jsonObject.getString("target").equals(AppointTimeActivity.mShow_TV_NetWorkstate)){
                            mNetworking = true;
                            mIVRing.setVisibility(View.VISIBLE);
                            mPBRing.setVisibility(View.GONE);
                            mTVNewFi.setText(R.string.wifi_networking);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    if(string.equals("balance")){
                        if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                            queryBalance();
                        }else if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 2){
                            updatePackage();
                        }
                    }
                    if(string.equals("vip")){
                        if(MyApplication.getApp().getSiteAreaid() >=10000 || MyApplication.getApp().getSiteAreaid() == 0){
                            HomeUtil.getHemeUtilNew().saveCombo(getActivity(),0,null);
                            updateView();
                        }
                    }
                    if(string.equals("SZ_NetWorkstate")){
                        mIVRing.setVisibility(View.VISIBLE);
                        mPBRing.setVisibility(View.GONE);
                        setTextViewText(WifiUtil.getInstance(getActivity()).getWIFIName(),true,0);
                        String param = (String) SharedPreferencesUtils.getParam(getActivity(),mWelComeVP,"");
                        if(param.equals("")){
                            setParam(getActivity(),mWelComeVP,"mWelComeVP");
                            CommomDialog commomDialog = new CommomDialog(getActivity());
                            commomDialog.show();
                        }
                    }
                    if(string.equals("NetWorkstate_ok")){
                        String param = (String) SharedPreferencesUtils.getParam(getActivity(),mWelComeVP,"");
                        if(param.equals("")){
                            setParam(getActivity(),mWelComeVP,"mWelComeVP");
                            CommomDialog commomDialog = new CommomDialog(getActivity());
                            commomDialog.show();
                        }
                    }
                    if(string.equals("wifl_view")){
                        wifiView(1);
                    }

                    if(string.equals("update_head_view")){
                        setTextViewText(WifiUtil.getInstance(getActivity()).getWIFIName(),false,0);
                    }
                }
            }
        }
    }

    /**
     * 显示续时
     */
    private void showRenew(){
        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 1){
            if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                String monryTime = (String) getParam(getActivity(),HomeUtil.mMoneyTime,"");  //上网的时间
                int time = (int) getParam(getActivity(),HomeUtil.mNetworkingTime,4);        //预约的时长
                long lon = StringUtil.getStringUtilNew().compareTime(monryTime,time);
                if(lon > 0){
                    mTVRenew.setVisibility(View.VISIBLE);
                }
            }
        }
    }

    /**
     * wifi 4g 改变时 调用
     */
    public void wifiView(int type){
        AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
            @Override
            public void onClick(boolean state) {
                if(!state){
                    inspectTVTime(1,state);
                }
            }
        });

        ArrayList list = (ArrayList) SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mAppPatternArray,"list");
        LogUtil.eE("wifiView","..list.."+list.size()+"..Pattern.."+MyApplication.getApp().getmPattern());
        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 1){
            getFFVISIBLE();
            showMiddleLeft(MyApplication.getApp().getmPattern());
            showMiddleRigth(MyApplication.getApp().getmPattern(),list);
        }else {
            showSchool();
        }

        if(type == 1){
            AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
                @Override public void onClick(boolean state) {setTextViewText(WifiUtil.getInstance(getActivity()).getWIFIName(),state,0);}});
        }

        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt1() == 6){
            final RetunDialog retunDialog = new RetunDialog(getActivity(),"",9,true);
            retunDialog.show();
        }
    }

    /**
     * 显示中间部分 左边的View
     */
    private void showMiddleLeft(int pattern1){
          if((boolean) getParam(getActivity(),HomeUtil.mVIPSTATE,true)){
              if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 1){
                  mIV1.setVisibility(View.GONE);
                  mTVTime.setVisibility(View.VISIBLE);
                  mTV1.setText("可用时长");
                  queryBalance();
              }else if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 2){
                  mTVTime.setVisibility(View.VISIBLE);
                  mIV1.setVisibility(View.GONE);
                  int days = (int)SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mPackage_RemainingDays,0);
                  if(days > 0){
                      mTVTime.setText(days+"天");
                  }else {
                      mTVTime.setText(0+"天");
                  }
                  mTV1.setText("我的套餐");
              }
          }else {
              mTVTime.setVisibility(View.VISIBLE);
              mIV1.setVisibility(View.GONE);
              mTV1.setText("可用时长");
              mTVTime.setText("--");
          }

    }

    /**
     * 显示中间部分 右边的View
     */
    private void showMiddleRigth(int pattern1,ArrayList list){
        if((boolean) getParam(getActivity(),HomeUtil.mVIPSTATE,true)){
            if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 1){
                mTV3.setText("时长充值");
            }else if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 2){
                mTV3.setText("套餐充值");
            }
        }else {
            if(list != null && list.size() == 1){
                if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 1){
                    mTV3.setText("时长充值");
                }else if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 2){
                    mTV3.setText("套餐充值");
                }else {
                    mTV3.setText("");
                }
            }else if(list != null && list.size() > 1){
                mTV3.setText("选择模式");
            }
        }
    }

    /**
     * 学校的显示
     */
   private void showSchool(){
       mLLMiddle.setVisibility(View.GONE);
   }

    /**
     * 显示 LL
     */
    private void getFFVISIBLE(){
        if( MyApplication.getApp().getSiteAreaid()>= 10000 ){
            mLLMiddle.setVisibility(View.VISIBLE);
        }else {
            mLLMiddle.setVisibility(View.GONE);
        }
    }

   /**
     * 打开wifi时改变UI
     */
    private void gWifiView(String wifiName,int type,boolean b){
        if(mNetworking){
            mIVRing.setVisibility(View.VISIBLE);
            mPBRing.setVisibility(View.GONE);
        }
        if(b){
            mIVWiFi.setBackgroundResource(R.mipmap.wifi_full);
        }else {
            mIVWiFi.setBackgroundResource(R.mipmap.wifi_nothing);
        }

        if (type == 0 || type == 3 || type == 4){
            mHandler.sendEmptyMessageDelayed(2, 1000);
        }
        if(type == 3){
            setTextViewText(wifiName,AgentIp.newInstance(getActivity()).isNetWorkstate(),3);
        }else if(type == 4){
            setTextViewText(wifiName,b,0);
        }else {
            setTextViewText(wifiName,b,0);
        }
    }

   /**
     * 改变头两个TV的显示内容
     */
    private void setTextViewText(String wifiName,boolean netWokstate,int type){
        mLogger.info("setTextViewText()....wifiName"+wifiName+"..netWokstate.."+netWokstate+"..type.."+type+"..SiteAreaid..."+MyApplication.getApp().getSiteAreaid()+"...Combo..."+MyApplication.getApp().getmPattern());
        if(MyApplication.getApp().getSiteAreaid() !=0){
            LogUtil.eE(""," "+1);
            if(netWokstate){
                mIVWiFi.setBackgroundResource(R.mipmap.wifi_full);
            }else {
                mIVWiFi.setBackgroundResource(R.mipmap.wifi_nothing);
            }
            if(netWokstate){
                mTVNewFi.setVisibility(View.GONE);
                if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                    showRenew();
                }else {
                    mTVRenew.setVisibility(View.GONE);
                    mTVWiFiName.setText("已连接"+WifiUtil.getInstance(getActivity()).getWIFIName()+",畅享网络");
                }
                if(type !=1 && type !=2){
                    LogUtil.eE("","............setTextViewText................"+2);
                    if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                        inspectTVTime(0,netWokstate);
                    }
                }
            }else {
                mTVRenew.setVisibility(View.GONE);
                if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                    inspectTVTime(1,netWokstate);
                }
                if(type !=2){
                    LogUtil.eE("","............setTextViewText................"+4);
                    mTVWiFiName.setText("已连接"+wifiName+",上网请点");
                }
                mTVNewFi.setVisibility(View.VISIBLE);
                mTVNewFi.setText(R.string.wifi_networking);
            }

        }else if(wifiName.equals("<unknown ssid>") || wifiName.equals("unknown ssid")){
            if(type !=1){mTVWiFiName.setText("未连接");}
            mTVNewFi.setText("连接NewFi");
            mTVNewFi.setVisibility(View.VISIBLE);
            mTVRenew.setVisibility(View.GONE);
            mIVWiFi.setBackgroundResource(R.mipmap.wifi_4g);
            if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 0){
                mTVWiFiName.setText("请打开Wi-Fi,土豪除外哦...");
                mTVNewFi.setText("去设置");
            }
        }else {
            mIVWiFi.setBackgroundResource(R.mipmap.wifi_space);
            if(MyApplication.getApp().getSiteAreaid() == 1 || MyApplication.getApp().getSiteAreaid() == 2){
                if(netWokstate){
                    mTVNewFi.setVisibility(View.GONE);
                    mTVWiFiName.setText("已连接"+wifiName+",畅享网络");
                    mTVRenew.setVisibility(View.GONE);
                }else {
                    mTVNewFi.setVisibility(View.VISIBLE);
                    mTVNewFi.setText(R.string.wifi_networking);
                    mTVWiFiName.setText("已连接"+wifiName+",上网请点");
                    mTVRenew.setVisibility(View.GONE);
                }
            }else {
                if(type !=1 && type !=2){
                    LogUtil.eE("","............setTextViewText................"+5);
                    mTVNewFi.setVisibility(View.VISIBLE);
                    if(MyApplication.getApp().getSiteAreaid() == 0 && !wifiName.equals("NewFi")){
                        mTVWiFiName.setText("已连接"+wifiName+",并非本app服务的热点");
                        mTVNewFi.setText("切换至NewFi");
                    }else {
                        mTVWiFiName.setText("已连接"+wifiName);
                        mTVNewFi.setText("上网");
                    }
                }
                mTVRenew.setVisibility(View.GONE);
            }
        }

        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 0){
            if(type !=3){
                mTVWiFiName.setText("请打开Wi-Fi,土豪除外哦...");
                mTVNewFi.setVisibility(View.VISIBLE);
                mTVNewFi.setText("去设置");
            }
        }

    }

    /**
     * 查询余额
     */
    private void queryBalance(){
        if((boolean)SharedPreferencesUtils.getParam(getActivity(),HomeUtil.AppAgainState,true)){
            if(MyApplication.getApp().getSiteAreaid() == 0){
                mAgainState = false;
            }
        }
        if(SharedPreferencesUtils.getParam(getActivity(), HomeUtil.mUseridDB, "0").equals("0")){
            mAgainState = false;
        }
        String url = "";
        HashMap<String,Object> mMap = new HashMap<>();
        mMap.put("userid",mId);
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(mMap); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngpcDeal_selectBalance,stringJson,mToken,mId,time);
        Map map = StringUtil.getStringUtilNew().getMapNew(getActivity(),stringJson,mToken,mId, Url.mStirngpcDeal_selectBalance,stirngSign,time);
        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt()  == 0){
            url = Url.getUrlNew().getAppIP();
        }else {
            url = MyApplication.getApp().getFWQString();
        }


        LogUtil.eE("fwq","  "+url);
        mLogger.info("queryBalance()--->查询余额--fwq"+url+"stirngSign"+stirngSign);

        GreenTreeNetworkUtil.getInstance().doPost(getActivity(),url,1,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    String code = jsonObject.getString("code");
                    LogUtil.eE("",response);
                    if(code.equals("1")) {
                        mLogger.info("queryBalance()--->onSuccess--String"+response);
                        mTime = (jsonObject.getInt("longTime")/60);
                        mTVTime.setText(mTime+"h");
                        setParam(getActivity(),HomeUtil.mVIPTime,jsonObject.getInt("longTime"));
                    }else if (code.equals("-2")) {
                        if(mAgainState){
                         CrowdRetunDialog crowdRetunDialog = new CrowdRetunDialog(getActivity());
                         crowdRetunDialog.show();
                        }
                    }else {
                        mTVTime.setText("- -");
                    }

                } catch (Exception e) {e.printStackTrace();}
            }

            @Override public void onFailure(Throwable error) {
                mTVTime.setText("- -");
            }
        });
    }

    /**
     * 更新天数
     */
    private void updatePackage(){
          HomeUtil.getHemeUtilNew().getHandlerNew().postDelayed(new Runnable() {
              @Override
              public void run() {
                  int days = (int)SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mPackage_RemainingDays,0);
                  if(days > 0){
                      mTVTime.setText(days+"天");
                  }else {
                      mTVTime.setText(0+"天");
                  }
              }
          },3000);
    }

    /**
     * 更新中间View
     */
    private void updateView(){
        HomeUtil.getHemeUtilNew().getHandlerNew().postDelayed(new Runnable() {
            @Override
            public void run() {
                ArrayList list = (ArrayList) SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mAppPatternArray,"list");
                getFFVISIBLE();
                showMiddleLeft(MyApplication.getApp().getmPattern());
                showMiddleRigth(MyApplication.getApp().getmPattern(),list);
            }
        },2000);
    }

    /**
     * mHandler msg为1
     */
    private void handlerMsg1(){
        mPollingNumber++;
        LogUtil.eE("hand","......................."+mPollingNumber);
        if(mPollingNumber == 10){
            mNetworking = true;
            gWifiView(WifiUtil.getInstance(getActivity()).getWIFIName(),0,false);
        }else {
            mList = WifiUtil.getInstance(getActivity()).getListScanResult();
            if(mList !=null){
                if(mList.size() == 0){
                    mHandler.sendEmptyMessageDelayed(1,1000);
                }else {
                    int newFiID = WifiUtil.getInstance(getActivity()).IsConfiguration("\""+mNewFiWiFi+"\"");
                    if(newFiID>0){
                        boolean d = WifiUtil.getInstance(getActivity()).ConnectWifi(newFiID);
                        if(!d){
                            WifiUtil.getInstance(getActivity()).ConnectWifi(WifiUtil.getInstance(getActivity()).IsConfiguration(mNewFiWiFi));
                        }
                        mNetworking = true;
                        mHandler.sendEmptyMessageDelayed(2,500);
                        mIVRing.setVisibility(View.VISIBLE);
                        mPBRing.setVisibility(View.GONE);
                    }else {
                        mHandler.sendEmptyMessageDelayed(1,1000);
                    }
                }
            }
        }
    }

    /**
     * mHandler msg为3
     */
    private void handlerMsg3(){
        mPollingNumber++;
        if(mPollingNumber >= 10){
            mNetworking = true;
            Toast.makeText(getActivity(),"连接失败,可以手动去系统WiFi列表连接",Toast.LENGTH_SHORT).show();
            gWifiView(WifiUtil.getInstance(getActivity()).getWIFIName(),0,false);
        }else {
            final String wifiName = WifiUtil.getInstance(getActivity()).getWIFIName();
            if(wifiName.equals(mNewFiWiFi)){
                AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
                    @Override
                    public void onClick(boolean state) {
                        gWifiView(wifiName,4,state);
                        mNetworking = true;
                        mList = WifiUtil.getInstance(getActivity()).getWifiList();
                        if(mList !=null){
                            mRecyclerWeWiFiAccount.showView(mList);
                            mRecyclerWeWiFiAccount.notifyDataSetChanged();
                        }
                    }
                });
            }else {
                mHandler.sendEmptyMessageDelayed(3,1000);
            }
        }
    }

    /**
     * mHandler msg为4
     */
    private void handlerMsg4(){
        HomeUtil.getHemeUtilNew().getHandlerNew().postDelayed(new Runnable() {
            @Override
            public void run() {
                LogUtil.eE("联网处理",".......handlerMsg4....mNetworking....."+mNetworking);
                try {
                    if(mNetworking == false){
                        netWorkstateJurisdictionNO();
                        Toast.makeText(getActivity(),"连接不顺，请重试或稍等",Toast.LENGTH_SHORT).show();
                    }
                }catch (Exception e){
                    LogUtil.eE("","出异常了");
                }
            }
        },18000);
    }

    /**
     * 判断网络的情况   13:19:23.001
     */
    private void getJudge(){
            mTVNewFi.setText("连接中");
            mIVRing.setVisibility(View.GONE);
            mPBRing.setVisibility(View.VISIBLE);
            HomeUtil.getHemeUtilNew().domainUtil(getActivity(),2500,new HomeUtil.OnHomeUtilClickListener() {
                @Override
                public void onItemClick(String type) {
                    mLogger.info("联网处理....string.。。。。检查网络。。。。。。。3。state。."+type);
                    if(type.equals("ok")){
                        mNetworking = true;
                        mTVNewFi.setVisibility(View.GONE);
                        mIVRing.setVisibility(View.VISIBLE);
                        mPBRing.setVisibility(View.GONE);
                        final RetunDialog retunDialog = new RetunDialog(getActivity(),"",5,true);
                        retunDialog.show();
                        HomeUtil.getHemeUtilNew().getHandlerNew().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                retunDialog.dismiss();
                            }
                        },1000);
                        setTextViewText(WifiUtil.getInstance(getActivity()).getWIFIName(),true,0);
                    }else {
                        getJudgeIP();
                    }
                }
            });
    }

    /**
     * 深大的联网
     */
    private void szNetWorkstate(){
        mEntryPromptDialog = new EntryPromptDialog(getActivity(),EntryPromptDialog.mStringEntry,"");
        mEntryPromptDialog.show();
    }

    public void getJudgeIP(){
        HashMap<String,Object> hashMap = new HashMap<>();
        if(mId.equals("")){
            hashMap.put("userid","0");
        }else {
            hashMap.put("userid",mId);
        }
        hashMap.put("visitType",1);
        hashMap.put("ip",getInformation.getNewGetInformation(getActivity()).getI_IP());
        hashMap.put("mac",getInformation.getNewGetInformation(getActivity()).getIMAC());
        hashMap.put("apMac",getInformation.getNewGetInformation(getActivity()).getWiFiMac());
        hashMap.put("apName",getInformation.getNewGetInformation(getActivity()).getWIFIName());
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(hashMap); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngVersion_isAlive,stringJson,"null","0",time);
        Map map = StringUtil.getStringUtilNew().getMapNew(getActivity(),stringJson,"null","0",Url.mStirngVersion_isAlive,stirngSign,time);
        mFwq = (String) getParam(getActivity(),HomeUtil.mFWQ,"");
        mLogger.info("测试代理....getJudgeIP()--->type"+"mFwq...."+mFwq+"..stringJson..."+stringJson+"...NF_callid..."+map.get("NF_callid"));
        GreenTreeNetworkUtil.getInstance().doPost(getActivity(),mFwq,3500,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                    mLogger.info("联网处理....string.。。。。检查代理。。。。。。。6。。SiteAreaid。。."+MyApplication.getApp().getSiteAreaid()+"..getmPattern.."+MyApplication.getApp().getmPattern()+"..apMac.."+getInformation.getNewGetInformation(getActivity()).getWiFiMac());
                    mLogger.info("getJudgeIP()--->onSuccess()+String--"+response);
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getInt("code") == 1) {
                        MyApplication.getApp().setFWQString(mFwq);
                        MyApplication.getApp().setSiteAreaid(jsonObject.getInt("siteAreaid"));
                        setParam(getActivity(), HomeUtil.mFWQ,mFwq);
                        isAliveOk();
                    }else {
                        mNetworking = true;
                        mIVRing.setVisibility(View.VISIBLE);
                        mPBRing.setVisibility(View.GONE);
                        mTVNewFi.setText(R.string.wifi_networking);
                        Toast.makeText(getActivity(),getString(R.string.FWQ),Toast.LENGTH_SHORT).show();}
                } catch (JSONException e) {
                    e.printStackTrace();
                    mLogger.info("getJudgeIP()--->onFailure()去走portal或+Throwable-解析出错-");
                    getJudgeIPON();
                }
            }

            @Override public void onFailure(Throwable error) {
                mLogger.info("getJudgeIP()--->onFailure()去走portal或+Throwable--"+error);
                getJudgeIPON();
            }});
    }

    private void getJudgeIPON(){
        mLogger.info("联网处理....string.。。。。检查代理。。。。。。。7。。失败.。。去找");
        AgentIp.newInstance(getActivity()).getIp(new AgentIp.OnAgentIpItemClickListener() {
            @Override
            public void onItemClick(String fwq) {
                mLogger.info("联网处理....string.。。。。检查代理。。。。。。。7—1。。失败.。。去找。。结果。。"+fwq);
                mLogger.info("getJudgeIP()--->网页获取的地址"+"String--"+fwq);
                if(fwq.equals("没有查到")){
                    mIVRing.setVisibility(View.VISIBLE);
                    mPBRing.setVisibility(View.GONE);
                    if(!mNetworking){
                      mNetworking = true;
                      Toast.makeText(getActivity(),"没有查找到代理服务器",Toast.LENGTH_SHORT).show();
                    }
                    mTVNewFi.setText(R.string.wifi_networking);
                }else {
                    if(!fwq.equals(MyApplication.mFWQIP)){
                        HomeUtil.getHemeUtilNew().saveCombo(getActivity(),0,null);
                        MyApplication.getApp().setFWQString(fwq);
                        setParam(getActivity(),HomeUtil.mFWQ,fwq);
                        isAliveOk();
                    }else {
                        mIVRing.setVisibility(View.VISIBLE);
                        mPBRing.setVisibility(View.GONE);
                        if(!mNetworking){
                            mNetworking = true;
                            Toast.makeText(getActivity(),"没有查找到代理服务器",Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            }
        });
    }

    /**
     * 检查是否要显示时间
     */
    private void inspectTVTime(int type,boolean b){
        String monryTime = (String) getParam(getActivity(),HomeUtil.mMoneyTime,"");  //上网的时间
        int time = (int) getParam(getActivity(),HomeUtil.mNetworkingTime,4);        //预约的时长
        long lon = StringUtil.getStringUtilNew().compareTime(monryTime,time);
        if(lon > 0){
            if(b){
                if(type == 0 ){
                    mLogger.info("inspectTVTime()..time"+lon);
                        if(mWiFiShowFV == null){
                            mWiFiShowFV = WiFiShowFV.newInstance(getActivity());
                            mWiFiShowFV.showTv(0,lon,mTVWiFiName);
                        }else {
                            mWiFiShowFV.changeTV(lon);
                        }
                    if(Url.getUrlNew().isNotification()){
                        Intent intent = new Intent(getActivity(),MyService.class);
                        intent.putExtra("type","ok");
                        getActivity().startService(intent);
                    }
                    HomeUtil.getHemeUtilNew().getHandlerNew().postDelayed(new Runnable() {@Override public void run() {Url.getUrlNew().setNotification(true);
                        }},3000);

                }
            }else {
                if(type !=0){
                    mLogger.info("inspectTVTime()..time.自动连接.."+time+"..ti.."+lon);
                    if(lon>0){
                        mTVWiFiName.setText("已连接"+WifiUtil.getInstance(getActivity()).getWIFIName()+",畅享网络");
                        if(mWiFiShowFV !=null){mWiFiShowFV.onPause();}
                        NetWorkstateUtil.getInstance().networkPlanInNet(getActivity());
                    }
                }
            }
        }else {
            if(b){
                if(mWiFiShowFV !=null){mWiFiShowFV.onPause();}
                mTVWiFiName.setText("已连接"+WifiUtil.getInstance(getActivity()).getWIFIName()+",畅享网络");
            }else {
                if(mWiFiShowFV !=null){mWiFiShowFV.onPause();}
                mTVWiFiName.setText("已连接"+WifiUtil.getInstance(getActivity()).getWIFIName()+",上网请点");
            }
        }
    }

    /**
     * 联通代理后的操作
     */
    private void isAliveOk(){
        if(MyApplication.getApp().getSiteAreaid() >= 10000 ){
                NetWorkstateUtil.getInstance().getNetworking(getActivity(),null,HomeUtil.ZHUYE);
        }else {
                if(MyApplication.getApp().getSiteAreaid() == 2){
                    NetWorkstateUtil.getInstance().getNetworking(getActivity(),null,HomeUtil.ZHUYE);
                }else if(MyApplication.getApp().getSiteAreaid() == 1){
                    netWorkstateJurisdictionNO();
                    szNetWorkstate();
                }else {
                    NetWorkstateUtil.getInstance().getNetworking(getActivity(),null,HomeUtil.ZHUYE);
                }
        }
    }

    /**
     * 获取福利数据  wifi
     */
    private void getWelfareData(){
        mMap = new HashMap<>();
        mMap.put("userid",mId);
        mMap.put("visitType",1);
        mMap.put("appType",1);
        mMap.put("siteAreaid",MyApplication.getApp().getSiteAreaid());
        mMap.put("framePage","wifi");
        mMap.put("pageSize",30);
        mMap.put("pageNum",1);
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(mMap); //参数包
        final long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.getUrlNew().url_pageHome,stringJson,mToken,mId,time);
        final Map map = StringUtil.getStringUtilNew().getMapNew(getActivity(),stringJson,mToken,mId,Url.getUrlNew().url_pageHome,stirngSign,time);
        mLogger.info("getWelfareData--广告->"+map.get("NF_callid")+"..stringJson..."+stringJson+"...NF_callid..."+map.get("NF_callid"));
        GreenTreeNetworkUtil.getInstance().doPost(getActivity(),MyApplication.getApp().getFWQString(),8000,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    mLogger.info("getWelfareData--response->"+response);
                    if (jsonObject.getInt("code") == 1) {
                        JSONArray jsonArray = jsonObject.optJSONArray("data");
                        if(jsonArray.length() != 0){
                            RecyclerWeWiFiAccount recyclerWeWiFiAccount = new RecyclerWeWiFiAccount(getActivity(),3,null,mList,jsonArray);
                            mRVWelfare.setAdapter(recyclerWeWiFiAccount);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override public void onFailure(Throwable error) {
                mLogger.info("getJudgeIP--->onFailure--->"+"time"+StringUtil.getStringUtilNew().getTimeInstance()+error);
            }
        });
    }

    /**
     * 联网 没授权
     */
    private void netWorkstateJurisdictionNO(){
        mTVNewFi.setText(R.string.wifi_networking);
        mNetworking = true;
        mIVRing.setVisibility(View.VISIBLE);
        mPBRing.setVisibility(View.GONE);
    }

    /**
     *断网 zz6556159
     */
    private void breakoff(){
        mTVNewFi.setVisibility(View.GONE);
        mIVRing.setVisibility(View.GONE);
        mPBRing.setVisibility(View.VISIBLE);
        NetWorkstateUtil.getInstance().getBrokenNetwork(getActivity(),new HomeUtil.OnHomeUtilClickListener() {
            @Override
            public void onItemClick(String type) {
                     AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
                         @Override
                         public void onClick(boolean state) {
                             mNetworking = true;
                             mIVRing.setVisibility(View.VISIBLE);
                             mPBRing.setVisibility(View.GONE);
                             if(state){
                                 mTVNewFi.setVisibility(View.GONE);
                                 if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 2){
                                     mTVRenew.setVisibility(View.GONE);
                                 }else {
                                     showRenew();
                                 }
                                 Toast.makeText(getActivity(), "断网失败", Toast.LENGTH_SHORT).show();
                             }else {
                                 if(mWiFiShowFV !=null){mWiFiShowFV.onPause();}
                                 mTVNewFi.setText(R.string.wifi_networking);
                                 mTVWiFiName.setText("已连接"+WifiUtil.getInstance(getActivity()).getWIFIName()+",上网请点");
                                 mTVRenew.setVisibility(View.GONE);
                                 Toast.makeText(getActivity(), "断网成功", Toast.LENGTH_SHORT).show();
                                 Intent intent = new Intent(getActivity(),MyService.class);
                                 intent.putExtra("type","on");
                                 getActivity().startService(intent);
                             }
                         }
                     });
            }
        },0);
    }

    /**
     * 查询 优惠券
     */
    private void getCoupon(){
        if((boolean)SharedPreferencesUtils.getParam(getActivity(),HomeUtil.AppAgainState,true)){
            if(MyApplication.getApp().getSiteAreaid() == 0){
                mAgainState = false;
            }

        }
        if(SharedPreferencesUtils.getParam(getActivity(), HomeUtil.mUseridDB, "0").equals("0")){
            mAgainState = false;
        }
        HomeUtil.getHemeUtilNew().getCoupon(getActivity(),new HomeUtil.OnCouponClickListener() {
            @Override
            public void onItemClick(String string) {
                try {
                    JSONObject jsonObject = new JSONObject(string);
                    mLogger.info("getCoupon()--onSuccess().."+string);
                    int code = jsonObject.getInt("code");
                    if(code == 1){
                        JSONArray jsonArray = jsonObject.getJSONArray("ticket");
                        LogUtil.eE("","................getCoupon().."+jsonArray.length()+"");
                        if(jsonArray.length()>0 ){
                            CouponDialog couponDialog = new CouponDialog(getActivity(),jsonArray);
                            couponDialog.show();
                        }
                    }else if(code == -2){
                        if(mAgainState){
                            CrowdRetunDialog crowdRetunDialog = new CrowdRetunDialog(getActivity());
                            crowdRetunDialog.show();
                        }
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }


    /**
     * 可视状态
     */
    @Override
    public void onResume() {
        super.onResume();
        mLogger.info("..............onResume()........可视状态....isonResumeJudge..."+Url.getUrlNew().isonResumeJudge()+"..url.."+ Url.getUrlNew());
        if(Url.getUrlNew().isonResumeJudge()){
            AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
                @Override
                public void onClick(boolean state) {
                    mLogger.info("..............onResume()........可视状态...state.."+state);
                    if(ismJudge){
                        gWifiView(WifiUtil.getInstance(getActivity()).getWIFIName(),0,state);
                    }
                }
            });
                LogUtil.eE("","getSiteAreaid...."+MyApplication.getApp().getSiteAreaid());
                if(MyApplication.getApp().getSiteAreaid() != 1 && MyApplication.getApp().getSiteAreaid() != 2 ){
                    if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                        queryBalance();
                    }else {
                        showMiddleLeft(MyApplication.getApp().getmPattern());
                    }
                }

        }
        Intent intent = new Intent(getActivity(),AlarmReceiver.class);
        intent.putExtra("networking","updateNetwork6");
        getActivity().sendBroadcast(intent);
    }

    /**
     * 初始化webView
     */
    private void initWebView(){
        WebView webView = new WebView(getActivity());
        String url = "http://119.29.54.250:8090/ad/adshow.do?userid="+mId+"&ip="+getInformation.getNewGetInformation(getActivity()).getI_IP()+"&mac="+getInformation.getNewGetInformation(getActivity()).getIMAC()+"&token="+mToken+"&siteAreaid="+MyApplication.getApp().getSiteAreaid();
        LogUtil.eE("initWebView",url);
        webView.loadUrl(url);
    }
}
